<?php
    session_name('dyh_session');
    session_start(); //start a session
    $redirect_url;
    if (!(isset($_SESSION['fname']) && isset($_SESSION['email']) && isset($_SESSION['payment']) && isset($_COOKIE['dyh_region']))){  //
        /*remove PHPSESSID cookie from browser, that was created by session_start() above.*/
        setcookie( session_name(), '', time()-3600, '/' );
        setcookie('dyh_region', '', time()-3600, '/');
        //user not registered so redirect to register page
        header('location:page2.html?lan=en');
        die();
    } else {
        //get cookie value for region and decide redirect url
        switch($_COOKIE['dyh_region']) {
            case "can1":
                $redirect_url = "can_en.php";
                break;
            case "us1":
                $redirect_url = "usa_en.php";
                break;
        }
    }
    //Thank you [Name] for your payment. Your transaction has been completed, and a receipt for your purchase has been emailed to you.
    //We are redirecting you to our Drawing Page now - in 10 secs.
    //If you are not redirected automatically then click this link.
?>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <style type="text/css">
        body, html {
            margin:0;
            padding:0;
            font-family: "Helvetica Neue", HelveticaNeue, "Helvetica-Neue", Helvetica, "BBAlpha Sans", sans-serif;
            font-size: 12px;
            font-weight: normal;
            color: #222;
            background:#EEEEEE;
            width:100%;
            height:100%;
        }
        .wrapper {
            width:100%;
            height:100%;
            position:relative;
        }
        .wrapperInner {
            width: 700px;
            height: 250px;
            position: absolute;
            top: 50%;
            margin-top: -125px;
            margin-left: -350px;
            left: 50%;
            background: #fff;
            border:1px solid #9a9a9a;
            border-radius: 3px;
        }
        .leftSide {
            width: 49%;
            height:100%;
            float:left;
        }
        .rightSide {
            width: 49%;
            height:100%;
            float:left;
        }
        .separator {
            width:1px;
            height: 200px;
            background: #ccc;
            float:left;
            margin-top: 25px;
        }
        p.title {
            position: absolute;
            top: 50%;
            font-size: 30px;
            left: 50%;
            font-family: sans-serif, verdana;
            margin-top: -170px;
            margin-left: -350px;
        }
        p.message {
            text-align:center;
        }

        .leftSide p.top {
            margin-top:95px;
        }
        .rightSide p.top {
            margin-top:100px;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <p class="title">Heart Preneur Inc.</p>
        <div class="wrapperInner">
            <div class="leftSide">
                <p class="message top">Thank you <b><?php echo $_SESSION['fname'] ?></b> for your payment.</p>
                <p class="message">Your transaction has been completed, and a receipt for your purchase has been e-mailed to you.</p>
            </div>
            <div class="separator"></div>
            <div class="rightSide">
            <p class="message top">We are redirecting you to our Drawing Page now - in 8 secs.</p>
            <p class="message">If you are not redirected automatically then click this <a href="<?php echo $redirect_url; ?>">link</a>.</p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        window.onload = function() {
            setTimeout(function() {
                //redirect
                //alert('redirect');
                location.href = "<?php echo $redirect_url; ?>";
            }, 8000);
        }
    </script>
</body>
</html>
